<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>



    <script>

        {
            
            // 定义一个类
            class User {
                constructor(name,pass){
                    this.name = name;
                    this.pass = pass;
                }

                showName () {
                    alert(this.name);
                }

                showPass () {
                    alert(this.pass);
                }
            }

            // 继承

            class SuperUser extends User {
                constructor (name,pass,level) {
                    super(name,pass); // -> 父类
                    this.level = level; 
                }

                showLevel(){
                    alert(this.level);
                }
            }

            let u = new SuperUser("ws","123456","10");

            u.showName();
            u.showPass();
            u.showLevel();

        }

        {
            class Ideal {

                init () {
                    this.showMsg();
                    this.showNum();
                }

                showMsg () {
                    console.log('show message');
                }

                showNum () {
                    console.log('show number');
                }

            }

            let ideal = new Ideal;

            ideal.init();
        }


        {

            class Product {

                constructor (data) {
                    this.data = data || {};
                }

                init () {
                    this.show();
                }

                show () {
                    console.log(this.data);
                }
            }

            let data = {
                code: 0,
                msg: 'success'
            }

            let p = new Product(data);

            p.init();
        }

        

    </script>
</body>
</html>